package com.cdp.zwy.zwy_manager_back_v1.controller;

import com.cdp.zwy.zwy_manager_back_v1.common.Result;
import com.cdp.zwy.zwy_manager_back_v1.entity.Admin;
import com.cdp.zwy.zwy_manager_back_v1.entity.Admin;
import com.cdp.zwy.zwy_manager_back_v1.service.AdminService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zwy
 * @version 1.0
 * @description: AdminController
 * @date 2025/4/14 19:02
 */
@CrossOrigin
@RestController
@RequestMapping("/admin")
public class AdminController {
    @Resource
    private AdminService adminService;
    @PostMapping("/add")
    public Result add(@RequestBody Admin admin){
        return Result.success(adminService.add(admin));
    }
    @GetMapping("/findAll")
    public Result findAll(){
        return Result.success(adminService.findAll());
    }
    @GetMapping("/findById/{id}")
    public Result findById(@PathVariable Integer id){
        return Result.success(adminService.findById(id));
    }
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id){
        return Result.success(adminService.deleteById(id));
    }
    @PutMapping("/modify")
    public Result modify(@RequestBody Admin admin){
        return Result.success(adminService.modify(admin));
    }
    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "2") Integer pageSize){
        return Result.success(adminService.selectPage(pageNum,pageSize));
    }
    @PostMapping("/findByName")
    public Result findByName(@RequestBody Admin admin, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "2") Integer pageSize){
        return Result.success(adminService.findByName(pageNum, pageSize,admin.getName()));
    }
    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Integer> ids){
        return Result.success(adminService.deleteBatch(ids));
    }

}
